;;; $Id: dump2man.el,v 1.3 2004/07/11 08:04:47 bhepple Exp $
(defun dump2man ()
  "Convert ##### to groff -man .BX\n
Remember to comment out any other # characters. \" not handled well"
  (interactive)
  (setq case-fold-search nil)
  (goto-char (point-min))
  (replace-regexp "^'" "\\\\&'")		; convert leading ' -> \&'
  (goto-char (point-min))
  (replace-regexp "^\\." "\\\\&.")		; convert leading . -> \&.
  (goto-char (point-min))
  (replace-string "\\" "\\e")			; convert \ -> \e
  (goto-char (point-min))
  (replace-regexp "^[ \t]*$" ".br\n\\\\0") 	; totally blank lines
  (goto-char (point-min))
  (replace-regexp " " "\\\\0")			; spaces to \0
  (goto-char (point-min))
  (replace-regexp "\\(.*#.*\\)" ".fi\n\\1\n.nf"); lines with # in them
  (goto-char (point-min))
  (replace-regexp "\\([^#]\\)#" "\\1\\\\c#")
  (goto-char (point-min))
  (replace-regexp "\\(#+\\)\\([^#\"\n]*\\)" "\n.BX \"\\1\" \"\\2\"\n"); ### fields
  (goto-char (point-min))
  (replace-regexp "^ " "")			; leading spaces
  (goto-char (point-min))
  (replace-regexp "^ *$" "")	 		; totally blank lines
  (goto-char (point-min))
  (replace-regexp "\n\n+" "\n")			; blank lines
  (goto-char (point-min))
  (replace-regexp "#" " ")
)
